package com.example.swagger.service;

import com.example.swagger.entity.Order;
import com.example.swagger.entity.User;
import com.example.swagger.mapper.OrderMapper;
import com.example.swagger.mapper.UserMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@Component
public class OrderService {
    @Autowired
    OrderMapper orderMapper;
    public void insertOrder(Order order) {
        orderMapper.insertOrder(order.getId(), order.getOrderId(), order.getOrderName(),order.getPrice(), order.getContent(), order.getCreateTime(), order.getUpdateTime(), order.getOrderNo());
    }

    public void deleteUserById(Integer id) {
        orderMapper.deleteOrder(id);
    }

    public void updateUser(Order order) {
        orderMapper.updateOrder(order.getId(), order.getOrderId(), order.getOrderName(),order.getPrice(), order.getContent(), order.getCreateTime(), order.getUpdateTime(), order.getOrderNo());
    }

    public Order queryOrderById(Integer id){
        return orderMapper.findOrderById(id);
    };

    public List<Order> queryAllOrders() {
        return orderMapper.getOrders();
    }

    public PageInfo<Order> getOrdersByPage(Integer pageNo, Integer pageSize) {
        PageHelper.startPage(pageNo,pageSize);
        PageInfo<Order> pageInfo = (PageInfo<Order>)orderMapper.getOrdersByPage(pageNo,pageSize);
        return pageInfo;
    }

    public void updateOrder(Order order) {
        orderMapper.updateOrder(order.getId(), order.getOrderId(), order.getOrderName(),order.getPrice(), order.getContent(), order.getCreateTime(), order.getUpdateTime(), order.getOrderNo());
    }
}
